<template>
  <div class="app-container">
    <el-dialog title="选择工艺路线" :visible.sync="open" width="1400px" v-dialogDrag append-to-body @close='close'>
      <!-- 搜索工作栏 -->
      <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="68px">
        <el-row>
          <el-col :span="4">
            <el-form-item label="路线名称" prop="name">
              <el-input v-model="queryParams.name" placeholder="请输入路线名称" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="路线代码" prop="code">
              <el-input v-model="queryParams.code" placeholder="请输入路线代码" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 列表 -->
      <el-table v-loading="loading" :data="list">
        <el-table-column label="序号" align="center" prop="id" />
        <el-table-column label="工厂" align="center" prop="factoryName" />
        <el-table-column label="部门" align="center" prop="deptName" />
        <el-table-column label="路线名称" align="center" prop="name" />
        <el-table-column label="路线代码" align="center" prop="code" />
        <el-table-column label="默认路线" align="center" prop="defaultRoute">
          <template v-slot="scope">
            <dict-tag :type="DICT_TYPE.SYSTEM_INTEGER_STATUS" :value="scope.row.defaultRoute" />
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status">
          <template v-slot="scope">
            <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="显示顺序" align="center" prop="sort" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template v-slot="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="selectProcessRoute(scope.row)" >选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList"/>
    </el-dialog>
    
  </div>
</template>

<script>
import { getProcessRoutePage } from "@/api/mes/processRoute";
import { getProcessRouteInfo } from "@/api/mes/processRouteInfo";
export default {
  name: "SelectProcessRoute",
  props: {
    openSelectProcessRoute: {
      required: true,
      default: false
    },
    factory: {
      required: true,
    }  
  },
  watch: {
    openSelectProcessRoute(newVal) {
      this.open = newVal;
    },
    factory(newVal) {
      this.factoryId = newVal;
    }
  },
  data() {
    return {
      open: this.openSelectProcessRoute,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品通用信息列表
      list: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        name: null,
        code: null,
        factoryId: this.factory
      },
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getProcessRoutePage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 选择产品 */
    selectProcessRoute(row) {
      getProcessRouteInfo(row.id).then(response => {
        row.routeInfo = response.data
        this.$emit('selectProcessRoute', row);
      })
      this.close()
    },
    close() {
      this.open = false;
      this.$emit('update:openSelectProcessRoute', this.open)
    }
  }
};
</script>

